# SPDX-License-Identifier: Apache-2.0

kernel_ld_options(${LINKERFLAGPREFIX},--no-undefined ${LINKERFLAGPREFIX},-X)

kernel_cc_options(-mgeneral-regs-only)
kernel_cc_options(-fno-asynchronous-unwind-tables)
kernel_cc_options(-mabi=lp64)

if(CONFIG_CPU_BIG_ENDIAN)
  target_compile_definitions(common_interface INTERFACE __AARCH64EB__)
  target_compile_options(kernel_interface INTERFACE -mbig-endian)
  target_link_libraries(kernel_interface
    INTERFACE
    ${LINKERFLAGPREFIX},-EB
    ${LINKERFLAGPREFIX},-maarch64elfb
  )
  set(UTS_MACHINE "aarch64_be" CACHE PATH "")
else()
  target_compile_definitions(common_interface INTERFACE __AARCH64EL__)
  target_compile_options(kernel_interface INTERFACE -mlittle-endian)
  kernel_ld_options(${LINKERFLAGPREFIX},-EL ${LINKERFLAGPREFIX},-maarch64elf)
  set(UTS_MACHINE "aarch64" CACHE PATH "")
endif()

if(CONFIG_LD_IS_LLD)
  target_link_libraries(kernel_interface
    INTERFACE
    ${LINKERFLAGPREFIX},-z,norelro
  )
endif()

add_subdirectory(boot)
add_subdirectory(kernel)
add_subdirectory(mm)
add_subdirectory(lib)
